//
//  dropMenuViewController.m
//  JFTRequest
//
//  Created by 竣付通 on 2017/11/13.
//  Copyright © 2017年 junHaoPay. All rights reserved.
//

#import "dropMenuViewController.h"
#import "XHPopMenu.h"
#import "JFTPopMenu.h"
@interface dropMenuViewController ()<JFTPopMenuDelegate>
@property (nonatomic,strong)JFTPopMenu *accountMenu;
@property (weak, nonatomic) IBOutlet UIButton *dropButton;
@property (weak, nonatomic) IBOutlet UIButton *XHPopMenuButton;
@property (nonatomic,strong) NSArray *dataArray;
@end

@implementation dropMenuViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
}
- (JFTPopMenu *)accountMenu{
    if (!_accountMenu) {
        _accountMenu = [[JFTPopMenu alloc] init];
        _accountMenu.frame = CGRectMake(self.dropButton.frame.origin.x,CGRectGetMaxY(self.dropButton.frame), 170, 100);
        _accountMenu.delegate = self;
        [self.view addSubview:_accountMenu];
    }
    return _accountMenu;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    self.dataArray = @[@"1",@"2",@"3",@"4",@"5"];
}

- (IBAction)dropDownButtonDidClick:(UIButton *)sender {
    [self.accountMenu initTableViewWithData:self.dataArray];
    self.accountMenu.hidden = false;
}
- (IBAction)XHPopMenuButtonDidClick:(UIButton *)sender {
    NSMutableArray<__kindof XHPopMenuItem *> *tempArr = [NSMutableArray array];
    for (int i=0; i<_dataArray.count; i++) {
        NSString  *str = [self.dataArray objectAtIndex:i];
        typeof(self) __weak weakSelf = self;
        XHPopMenuItem *model = [[XHPopMenuItem alloc] initWithTitle:str image:nil block:^(XHPopMenuItem *item) {
            [weakSelf.XHPopMenuButton setTitle:str forState:UIControlStateNormal];
        }];
        [tempArr addObject:model];
    }
    [XHPopMenu showMenuWithView:self.XHPopMenuButton menuItems:tempArr withOptions:nil];
}

#pragma mark -JFTPopMenuDelegate
-(void)jftPopMenuDidSelectWithObject:(id)object{
    NSString *str = object;
    [self.dropButton setTitle:str forState:UIControlStateNormal];
    self.accountMenu.hidden = YES;
    
}

@end
